<template>
  <div id="app">
    <form @submit.prevent="diagnose">
      <label for="name">姓名：</label>
      <input type="text" id="name" name="name" v-model="patient.name"><br><br>

      <label for="age">年龄：</label>
      <input type="number" id="age" name="age" v-model="patient.age"><br><br>

      <label for="height">身高：</label>
      <input type="number" id="height" name="height" v-model="patient.height" step="0.01" unit="米"><br><br>

      <label for="weight">体重：</label>
      <input type="number" id="weight" name="weight" v-model="patient.weight" unit="公斤"><br><br>

      <label for="medicalHistory">病史：</label>
      <textarea id="medicalHistory" name="medicalHistory" v-model="patient.medicalHistory" style="width: 165px;height: 20px;"></textarea><br><br>

      <button type="submit">诊断</button>
    </form>
    <p>患者 {{ patient.name }} 的诊断结果：{{ bmiResult }}</p>
  </div>
</template>
s
<script>
export default {
  data() {
    return {
      patient: {
        name: '',
        age: 0,
        height: 0,
        weight: 0,
        medicalHistory: ''
      },
      bmiResult: ''
    };
  },
  methods: {
    diagnose() {
      // 计算 BMI
      const bmi = this.patient.weight / (this.patient.height * this.patient.height);
      // 判断是否健康
      if (bmi < 18.5) {
        this.bmiResult = "体重过轻";
      } else if (bmi >= 18.5 && bmi < 24.9) {
        this.bmiResult = "体重正常";
      } else if (bmi >= 25 && bmi < 29.9) {
        this.bmiResult = "体重过重";
      } else {
        this.bmiResult = "肥胖";
      }
    }
  }
};
</script>

<style>
/* 在这里添加样式 */
</style>
